<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
set_time_limit(0);

//
require(dirname(dirname(__FILE__)) . '/includes/application_top.php');

//
include_once(CONFIG_PATH . CONFIG_DIR_INCLUDES . 'functions/thumb.function.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.directory.class.php');

//
function _generate_image($dir, $path, $path_resized) {
	$dObj = new CoreDirectory($path, $dir);
	$dObj->parse();
	$files = $dObj->getFiles();
	$dirs = $dObj->getDirs();
	
	//
	echo 'Start ...' . '<br>';
	echo $dir . '<br>';
	
	//
	if( is_array($files) ) {
		foreach($files as $k => $v) {
			$file = strtolower($v['file']);
			if( $v['file'] !== $file ) {
				echo $file . '<br>';	
			}
			if( substr($file, -5) == '.jpeg' || substr($file, -4) == '.jpg' || substr($file, -4) == '.bmp' || substr($file, -4) == '.gif' || substr($file, -4) == '.png' ) {
				$image = $dir . $file;
				$origin_file = $path . $image;
								
				//resized
				$thumb_file = $path_resized . substr($image, 0, strrpos($image, '.')) . '.jpg';
				$thumb_width = 500;
				$thumb_height = 500;
				if( !file_exists($thumb_file) ) {
					func_thumb_generate_thumb($origin_file, $thumb_file, $thumb_width, $thumb_height);
				}
			} else {
				echo $file . '<br>';	
			}
		}
	}
	
	//
	echo 'End' . '<br>';
}

//
$dir = '';
$path = CONFIG_PATH . 'images/A/Photo/';
$path_resized = CONFIG_PATH . 'images/A/PhotoRS/';
_generate_image($dir, $path, $path_resized);

//
echo 'OK';
//
?>